import { request } from '@@/plugin-request/request';
import { Params } from '@/pages/credit-transfer/credit-transfer.props';

export const getMortgageListStatus = async ({
  productCode,
}: {
  productCode: string;
}) => {
  try {
    const res = await request('/api/daas/dvas/v1/mortgage/list/status/count', {
      method: 'get',
      params: { productCode },
    });

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getMortgageList = async (params?: Params) => {
  try {
    const res = await request('/api/daas/dvas/v1/mortgage/list', {
      method: 'get',
      params: {
        current: 1,
        size: 10,
        ...(params || {}),
      },
    });

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getProductAmountInfo = async () => {
  try {
    const res = await request(
      '/api/daas/dvas/v1/product/info/getProductAmountInfo',
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getProductMaturityInfo = async () => {
  try {
    const res = await request(
      '/api/daas/dvas/v1/product/info/getMaturityMortgage',
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getMortgageInfo = async (id?: string) => {
  try {
    const res = await request(
      `/api/daas/dvas/v1/mortgage/info/${id || '5786'}`,
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getMortgageOperationLogInfo = async (id?: string) => {
  try {
    const res = await request(
      `/api/daas/dvas/v1/mortgageOperationLog/info/${id || '5786'}`,
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getMortgageReceivable = async (id?: string) => {
  try {
    const res = await request(
      `/api/daas/dvas/v1/mortgage/receivable/${id || '5786'}`,
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getApplyOrderList = async (id?: string) => {
  try {
    const res = await request(
      `/api/daas/dvas/v1/payment/apply/order/list/${
        id || 'YHQJ_1631169403288'
      }`,
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};

export const getApplyInvoiceList = async (id?: string) => {
  try {
    const res = await request(
      `/api/daas/dvas/v1/payment/apply/invoice/list/${
        id || 'YH_1631169400066'
      }`,
      {
        method: 'get',
      },
    );

    if (res?.code === '0000') return res.result;

    return null;
  } catch (e) {
    return null;
  }
};
